#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
struct Student{
	string name;
	int score[4];
};
bool cmp(Student x,Student y){
	int sum_x = x.score[0]+x.score[1]+x.score[2]+x.score[3];
	int sum_y = y.score[0]+y.score[1]+y.score[2]+y.score[3];
	return sum_x>sum_y;
}

Student stu[50];


int main(){
	int n; 
	cin >> n;
	for(int i=0;i<n;i++){
		cin >> stu[i].name;
		for(int j=0;j<4;j++){
			cin >> stu[i].score[j];
		}
	}
	sort(stu,stu+n,cmp);
	for(int i=0;i<3;i++){
		cout << stu[i].name << endl;
	}
	return 0;
}
